/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.gis.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.alibaba.fastjson.JSONArray;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
* @website https://el-admin.vip
* @description /
* @author ZHUANGBING YAN
* @date 2022-09-08
**/
@Entity
@Data
@Table(name="gis_transportation")
public class Transportation implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "主键")
    private Long id;

    @Column(name = "`line`")
    @ApiModelProperty(value = "路径线路")
    private String line;

    @Column(name = "`content`")
    @ApiModelProperty(value = "表示数据储存content:[{enter_time:入场时间,type:垃圾类别, //1建筑垃圾（装修） 2建筑垃圾（拆迁） 3建筑垃圾（拆建）status:是否违约weight: 净重id:对应主ID } ]")
    private String content;

    @Column(name = "`sum_weight`")
    @ApiModelProperty(value = "运输线总净重")
    private BigDecimal sumWeight;

    @Column(name = "`type`")
    @ApiModelProperty(value = "0/false是运输进入，1/true是运输出去")
    private Boolean type;

    @Column(name = "`area`")
    @ApiModelProperty(value = "地点(火星坐标系的经纬度)")
    private String area;


    @Column(name = "`status`")
    @ApiModelProperty(value = "是否异常")
    private Integer status;

    @Column(name = "`luguo`")
    @ApiModelProperty(value = "路过")
    private String luguo;


    public List<double[]> getPoline(){
        try {
            return JSONArray.parseArray(this.line,double[].class);
        }catch (Exception e){
            return null;
        }

    }

    public void copy(Transportation source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
